package com.bappi.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.weighttracker.android.R;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.Align;

public class ImageUtils {
	
	public static final Bitmap getResizeImage(Bitmap bitmap, int width,
			int height) {
		Bitmap ret = Bitmap
				.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		Canvas comboImage = new Canvas(ret);
		Rect r1 = new Rect(0, 0, width, height);
		Rect r2 = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		comboImage.drawBitmap(bitmap, r2, r1, null);
		comboImage.save();
		return ret;
	}
	
	private static final SimpleDateFormat MONTH =  new SimpleDateFormat("MMM");
	private static final SimpleDateFormat DAY =  new SimpleDateFormat("dd");
	
	public static final Bitmap getCalendarImage(Resources res,float dpiFactor) {

		Bitmap temp1 = BitmapFactory.decodeResource(res, R.drawable.calendar);
		Bitmap ret = Bitmap.createBitmap(temp1.getWidth(), temp1.getHeight(),
				Bitmap.Config.ARGB_8888);
		Canvas comboImage = new Canvas(ret);
		Rect r1 = new Rect(0, 0, temp1.getWidth(), temp1.getHeight());
		comboImage.drawBitmap(temp1, r1, r1, null);
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setColor(0xFFFFFFFF);
		paint.setTextSize(30*dpiFactor);
		paint.setTextAlign(Align.CENTER);
		paint.setTypeface(Typeface.DEFAULT_BOLD);
		Date date =  new Date();
		comboImage.drawText(MONTH.format(date),temp1.getWidth()/2,64*dpiFactor,paint);
		paint.setTextSize(80*dpiFactor);
		paint.setColor(0xFF000000);
		comboImage.drawText(DAY.format(date),temp1.getWidth()/2,164*dpiFactor,paint);
	
//		comboImage.drawText(printValue, temp2.getWidth() / 2,
//				3 * temp2.getWidth() / 4, paint);
		comboImage.save();
		return ret;
	}
}
